<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=XPFOXZxZCZwuGqFninoYGjkPiXhPt5uu"></script>
    <title>自定义网格</title>
    <style type="text/css">
        body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #allmap{width:100%;height:500px;}
        #r-result{width:100%;margin-top:5px;}
        p{margin:5px; font-size:14px;}
    </style>
</head>
<body>
<div id="allmap"></div>
<div id="r-result">
    <input type="button" onclick="add_control();" value="添加" />
    <input type="button" onclick="delete_control();" value="删除" />
</div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");            // 创建Map实例
    var point = new BMap.Point(116.404, 39.915); // 创建点坐标
    map.centerAndZoom(point,15);                 // 初始化地图,设置中心点坐标和地图级别。
    map.enableScrollWheelZoom();                 //启用滚轮放大缩小
    var tileLayer = new BMap.TileLayer({isTransparentPng: true});
    tileLayer.getTilesUrl = function(tileCoord, zoom) {
        var x = tileCoord.x;
        var y = tileCoord.y;
        return "http://lbsyun.baidu.com/jsdemo/img/border.png";
    }
    function add_control(){
        map.addTileLayer(tileLayer);
    }
    function delete_control(){
        map.removeTileLayer(tileLayer);
    }
    add_control();
</script>
